//leetcode 129 从根节点到叶结点数字之和
public class Test4 {
    public int sumNumbers(TreeNode root) {
        return dfs(root, 0);
    }

    private int dfs(TreeNode root, int n) {
        if (root == null) return 0;
        n = n * 10 + root.val;
        if (root.left == null && root.right == null) return n;
        int l = dfs(root.left, n);
        int r = dfs(root.right, n);

        return l + r;
    }
}
